﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Photo.Application.System.BuildCode.Dto
{
    /// <summary>
    /// 表字段dto
    /// </summary>
    public class TableColumnDto
    {
        /// <summary>
        /// 字段名称
        /// </summary>
        public string DbColumnName { get;set; }
        /// <summary>
        /// 字段描述
        /// </summary>
        public string ColumnDescription { get; set; }
        /// <summary>
        /// 字段类型
        /// </summary>
        public string DataType { get; set; }
        /// <summary>
        /// 是否可空
        /// </summary>
        public bool IsNullable { get; set; }
        /// <summary>
        /// 实体类类型
        /// </summary>
        public string EntityType
        {
            get
            {
                var result = "";
                switch (DataType)
                {
                    case "int":
                        result = "int";
                        break;
                    case "bigint":
                        result = "long";
                        break;
                    case "text":
                    case "varchar":
                        result = "string";
                        break;
                    case "decimal":
                        result = "decimal";
                        break;
                    case "bit":
                        result = "bool";
                        break;
                    case "datetime":
                    case "date":
                    case "time":
                        result = "DateTime";
                        break;
                    default:
                        break;
                }
                if (IsNullable && result != "string")
                {
                    result += "?";
                }
                return result;
            }
        }
    }
}
    